home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra_2 / flmgmtcl.zip / PATH.H < prev    next >
C/C++ Source or Header  |  1995-11-02  |  12KB  |  308 lines

  1. // ==========================================================================
  2. //                             Class Specification : CPathSpec
  3. // ==========================================================================
  4.  
  5. // Header file : path.h
  6.  
  7. // Source : Periphere NV (R.Mortelmans)
  8. // Creation Date :        2nd November. 1995
  9. // Last Modification : 2nd November. 1995
  10.                           
  11. // //////////////////////////////////////////////////////////////////////////
  12.  
  13. // Properties:
  14. //    NO    Abstract class (does not have any objects)
  15. //    YES    Derived from CDirSpec and CFileSpec
  16.  
  17. //    NO    Is a Cwnd.                     
  18. //    NO    Two stage creation (constructor & Create())
  19. //    NO    Has a message map
  20. //    NO Needs a resource (template)
  21.  
  22. //    NO    Persistent objects (saveable on disk)      
  23. //    NO    Uses exceptions
  24.  
  25. // //////////////////////////////////////////////////////////////////////////
  26.  
  27. // Desciption :         
  28. //        This class encapsulates a path specification
  29. //        A file specification consists of a directory (drive and subdirectory)
  30. //         and a file name (base name and extender) and file attributes (length, ...)
  31. //        All member functions starting with "Do" will physically change something
  32. //         on disk.  Other functions only change the internal data.
  33. //        E.g. The normal destructor only destroys the internal representation,
  34. //         to actually remove a directory use DoRemove()
  35.  
  36. // Remark:
  37. //        
  38.  
  39. // Prerequisites (necessary conditions):
  40. //        
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. #ifndef __PATH_H__
  44. #define __PATH_H__
  45.  
  46. #include "dir.h"
  47. #include "file.h"
  48. #include "pathiter.h"
  49.  
  50. class CPathSpec : public CDirSpec, public CFileSpec
  51. {
  52. DECLARE_DYNAMIC(CPathSpec)
  53.  
  54. // Data members -------------------------------------------------------------
  55. public:
  56.     
  57. protected:
  58.  
  59. private:
  60.     
  61. // Member functions ---------------------------------------------------------
  62. public:
  63.     CPathSpec();
  64.     // --- In  :
  65.     // --- Out : 
  66.     // --- Returns :
  67.     // --- Effect : Contructor of object
  68.     //                It will initialize the internal state
  69.  
  70.     CPathSpec(const char* pszPath);
  71.     // --- In  : pszPath : The new path name of the object
  72.     // --- Out : 
  73.     // --- Returns : 
  74.     // --- Effect : 
  75.     // --- Effect : Contruction of an object together with a SetPath()
  76.     //                Notice that whether the path specification is valid or not
  77.     //                cannot be checked in this way
  78.     
  79.     CPathSpec(const CPathSpec& pathSrc);
  80.     // --- In :    pathSrc : Path object which will be copied
  81.     // --- Out : 
  82.     // --- Returns :
  83.     // --- Effect : Copy contruction.
  84.     
  85.     const CPathSpec& operator=(const CPathSpec& pathSrc);
  86.     // --- In :    pathSrc : Path object which will be assign to 'this' file object
  87.     // --- Out:
  88.     // --- Returns: 
  89.     // --- Effect : Assignment operator
  90.     
  91.     CString GetPath() const;
  92.     // --- In  :
  93.     // --- Out : 
  94.     // --- Returns :The path specification  of this object
  95.     // --- Effect : 
  96.     BOOL SetPath(const char* pszPath);
  97.     // --- In  : pszPath : The new path specification of the object
  98.     // --- Out : 
  99.     // --- Returns : Whether path has a correct format
  100.     //                 Wild characters only allowed in the file specification
  101.     // --- Effect : 
  102.     void ForceSetPath(const char* pszPath);
  103.     // --- In  : pszPath : The new path specification of the object
  104.     // --- Out : 
  105.     // --- Returns : 
  106.     // --- Effect : This function extracts illegal characters and thus
  107.     //                will always succeeds
  108.     
  109.     BOOL SetPath(const CDirSpec dirSpec, const CFileSpec fileSpec);
  110.     // --- In  : dirSpec : The directory part of the new path
  111.     //           fileSpec : The file part of the new path
  112.     // --- Out : 
  113.     // --- Returns : Whether path has a correct format
  114.     // --- Effect : 
  115.     
  116.     CString GetShortDescription();
  117.     // --- In  :
  118.     // --- Out : 
  119.     // --- Returns :The path specification with all but the last subdirectory 
  120.     //              replaced by a double full stop
  121.     //                (E.g. C:\ONE\TWO\THREE\test.txt becomes C:\..\THREE\test.txt)
  122.     // --- Effect : 
  123.         
  124.     BOOL MakeTemp(BOOL bCreateEmpty = TRUE, const char* pszPrefix = TEXT("TMP"));
  125.     // --- In  : bCreateEmpty : Whether to create an empty file with the resulting name
  126.     //             pszPrefix : Prefix that will be used in the temporary file name
  127.     //                         Only the first three characters will be used
  128.     // --- Out : 
  129.     // --- Returns : Whether a unique path spec could be determined
  130.     // --- Effect : Replaces the path specification by that of the unique
  131.     //                temporary file
  132.     //                By default an empty temporary file with that name will be created on disk
  133.     
  134.     BOOL MakeAbsolute();
  135.     // --- In  : 
  136.     // --- Out : 
  137.     // --- Returns : Whether path has a correct format
  138.     // --- Effect : Replaces the path specification by an absolute path specification
  139.     
  140.     BOOL MakeUnique();
  141.     // --- In  : 
  142.     // --- Out : 
  143.     // --- Returns : Whether a unique file name could be made
  144.     // --- Effect : Replaces the file specification by another file specification
  145.     //                that does not yet exist on disk
  146.     //                So this can be used to make unique file names
  147.     
  148.     BOOL Exists() const;
  149.     // --- In  : 
  150.     // --- Out : 
  151.     // --- Returns : Whether the path physically exists on disk
  152.     // --- Effect : 
  153.     
  154.     BOOL IsEmpty() const;
  155.     // --- In  : 
  156.     // --- Out : 
  157.     // --- Returns : Whether the path specification is empty
  158.     // --- Effect : 
  159.     
  160.     void Empty();
  161.     // --- In  : 
  162.     // --- Out : 
  163.     // --- Returns : 
  164.     // --- Effect : CLears the path specification
  165.     
  166.     BOOL GetFirstFile(CPathIterator& Iterator) const;
  167.     // --- In  :
  168.     // --- Out : A CPathIterator value that can be used for iteration or object pointer
  169.     //                 retrieval; Invalid iterator if the the dir is empty.
  170.     // --- Returns : Whether the iterator is valid or not
  171.     // --- Effect : Gets the CPathIterator pointer to the first file
  172.     //                of this dir.
  173.     
  174.     CFileSpec GetNextFile(CPathIterator& Iterator) const;
  175.     // --- In  : 
  176.     // --- Out : FIterator : a reference to a CPathIterator returned by a previuos call
  177.     //                      to GetFirstFile or GetNextFile
  178.     // --- Returns : the file specification that represents the CPathIterator
  179.     // --- Effect : Gets the list element identified by CPathIterator, then sets
  180.     //                CPathIterator to the CPathIterator value of the next file in the dir
  181.     //                You can use GetNextFile in a forward iteration loop if
  182.     //                you establish the initial CPathIterator with a call to
  183.     //                GetFirstFile.
  184.     //                If the retrieved CFileSpec is the last in the dir, then
  185.     //                CPathIterator is in his INVALID state (check the IsItValid function) .
  186.     
  187.     BOOL GetFirstDir(CPathIterator& Iterator) const;
  188.     // --- In  :
  189.     // --- Out :
  190.     // --- Returns : A void pointer value that can be used for iteration or object pointer
  191.     //                 retrieval; NULL if the the dir is empty.
  192.     // --- Effect : Gets the void pointer to the fileinfo of the first subdir
  193.     //                of this dir.
  194.     
  195.     CDirSpec GetNextDir(CPathIterator& Iterator) const;
  196.     // --- In  : 
  197.     // --- Out : FIterator : a reference to a fileinfo returned by a previuos call
  198.     //                      to GetFirstDir or GetNextDir
  199.     // --- Returns : the dir specification that represents the pFInfo
  200.     // --- Effect : Gets the dir element identified by pFInfo, then sets
  201.     //                pFInfo to the fileinfo value of the next subdir in the dir
  202.     //                You can use GetNextDir in a forward iteration loop if
  203.     //                you establish the initial fileinfo with a call to
  204.     //                GetFirstDir.
  205.     //                If the retrieved CDirSpec is the last in the dir, then
  206.     //                CPathIterator is in his INVALID state (check the IsItValid function) .
  207.     
  208.     BOOL DoSearch(CFileSpec fileName, CDirSpec startingDir = CDirSpec(), BOOL bRecursively = FALSE);
  209.     // --- In  : fileName : The name of the file to search for (must not include wild chars)
  210.     //             startingDir : The directory in which to search
  211.     //             bRecursively : Whether subdirectories of the specified directory 
  212.     //                           should be searched as well
  213.     // --- Out : 
  214.     // --- Returns : Whether specified file was found
  215.     // --- Effect : Searches for the specified file and assigns the result to this object
  216.     //                The search order is :
  217.     //                    1 - The specified directory if the directory specification is not empty
  218.     //                    2 - Subdirectories of the specified directory if
  219.     //                        the directory specification is not empty and bRecursively is TRUE
  220.     //                        (This is not yet implemented)
  221.     //                    3 - The directory that contains the executable file of this running program
  222.     //                    4 - The current directory
  223.     //                    5 - The Windows directory
  224.     //                    6 - The System directory
  225.     //                    7 - The directories specified in the PATH-environment variable
  226.     
  227.     BOOL DoCopy(CPathSpec destinationPath) const;    
  228.     // --- In  : destinationPath : To destination to where the file must be
  229.     //                                copied.  The filename may be empty.
  230.     // --- Out : 
  231.     // --- Returns : Whether it succeeded or not
  232.     // --- Effect : Physically copies the contents of one file into another
  233.     //                When the detination file already exists, it will be truncated
  234.     
  235.     BOOL DoMove(CPathSpec destinationPath) const;    
  236.     // --- In  : destinationPath : To destination to where the file must be
  237.     //                                renamed or moved.  The filename must not be empty.
  238.     // --- Out : 
  239.     // --- Returns : Whether it succeeded or not
  240.     // --- Effect : Physically renames or moves the file to another name or location
  241.     //                When the destination file already exists, it will be truncated
  242.     //                Directories cannot be renamed on moving across disks is not supported
  243.     
  244.     BOOL DoRemove(BOOL bIgnoreReadOnly = FALSE) const;    
  245.     // --- In  : bIgnoreReadOnly : Whether the file should be removed,
  246.     //                       even when it is read-only
  247.     // --- Out : 
  248.     // --- Returns : Whether it succeeded or not
  249.     // --- Effect : Removes the directory
  250.  
  251.     BOOL DoGetInfo();
  252.     // --- In  : 
  253.     // --- Out : 
  254.     // --- Returns : Whether it succeeded or not
  255.     // --- Effect : Get the real time, file length and attributes from disk
  256.     //                and puts them in this path specification
  257.  
  258.     BOOL DoSetTime();
  259.     // --- In  : 
  260.     // --- Out : 
  261.     // --- Returns : Whether it succeeded or not
  262.     // --- Effect : Makes the real  time of the file on disk equal to the
  263.     //                time specified in the path specification
  264.         
  265.     BOOL DoSetLength();
  266.     // --- In  : 
  267.     // --- Out : 
  268.     // --- Returns : Whether it succeeded or not
  269.     // --- Effect : Makes the real length of the file on disk equal to the
  270.     //                length specified in the path specification
  271.         
  272.     BOOL DoSetAttributes();
  273.     // --- In  : 
  274.     // --- Out : 
  275.     // --- Returns : Whether it succeeded or not
  276.     // --- Effect : Makes the real attributes of the file on disk equal to the
  277.     //                attributes specified in the path specification
  278.     //                Notice that other function may change the attribute as a
  279.     //                side effect (archive attribute)
  280.     
  281. #ifdef _DEBUG
  282.     virtual void Dump(CDumpContext&) const;
  283.     virtual void AssertValid() const;
  284. #endif //_DEBUG
  285.  
  286.     virtual ~CPathSpec();
  287.     // --- In  :
  288.     // --- Out : 
  289.     // --- Returns :
  290.     // --- Effect : Destructor of object
  291.  
  292.     void* operator new(size_t nSize);
  293.     void operator delete(void* p);
  294.     // This functions must be overloaded, because both direct parents of CPathSpec,
  295.     // namely CDirSpec and CFileSpec are derived from CObject
  296.     // So this is done to unambiguize
  297. protected:      
  298.     static HMODULE GetThisModule();
  299.     static BOOL SearchEnvironment(const char* pszFileName, const char* pszVarName, char* pszPathName);
  300.     static DWORD GetEnvironmentVar(const char* pszVarName, char* pszValue, DWORD nLength);
  301.  
  302. private:
  303.                    
  304. };
  305.  
  306. #endif
  307. // ==========================================================================
  308.